package com.hospital.service.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hospital.service.project.entity.ProInfoBase;
import com.hospital.service.project.entity.help.ProInfoBaseHelp;
import com.hospital.service.project.model.param.*;
import com.hospital.service.project.model.vo.ProInfoBaseVo;
import com.hospital.service.project.model.vo.ProInfoBaseVo3;
import com.hospital.service.project.service.ProInfoBaseService;
import com.hospital.service.project.service.impl.ProInfoBaseServiceImpl;
import common.core.util.CommonUtil;
import common.core.util.ExcelUtil;
import common.core.util.Result;
import common.core.util.SystemLog;
import enhance.plus.logic.LogicBaseController;
import enhance.plus.util.Page;
import enhance.plus.util.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;


/**
 * 实验项目基本表 控制器
 *
 * @author xhl
 * @created 2020-10-10 13:58:34
 */
@Slf4j
@Validated
@RestController
@Api(tags = "实验项目基本表")
@RequestMapping("/project/proInfoBase")
public class ProInfoBaseController extends LogicBaseController<ProInfoBaseService, ProInfoBase> {

    private ProInfoBaseService proInfoBaseService;

    @Autowired
    public ProInfoBaseController(ProInfoBaseServiceImpl proInfoBaseServiceImpl) {
        this.proInfoBaseService = proInfoBaseServiceImpl;
    }

    @ApiOperation(value = "增加父项目")
    @SystemLog(value = "增加父项目", logo = "projectNumber")
    @RequestMapping(value = "/saveParent" , method = RequestMethod.PUT)
    public Result saveParent(@Valid @RequestBody ProInfoBaseParam param){
        log.debug("开始增加父项目-->{}",param);
        this.proInfoBaseService.save(param);
        return Result.success();
    }

    @ApiOperation(value = "增加子项目")
    @SystemLog(value = "增加子项目", logo = "projectNumber")
    @RequestMapping(value = "/saveSon" , method = RequestMethod.PUT)
    public Result saveSon(@Valid @RequestBody ProInfoBaseSaveSonParam param){
        log.debug("开始增加父项目-->{}",param);
        this.proInfoBaseService.save(param);
        return Result.success();
    }

    @ApiOperation(value = "更新实验项目基本表的数据")
    @SystemLog(value = "更新实验项目", logo = "projectNumber")
    @RequestMapping(value = "/update" , method = RequestMethod.PUT)
    public Result update(@Valid @RequestBody ProInfoBaseUpdateParam param){
        log.debug("开始跟新实验项目基本表-->{}",param);
        this.proInfoBaseService.updateProject(param);
        return Result.success();
    }

    @ApiOperation(value = "删除实验项目基本表的一条数据")
    @RequestMapping(value = "/delete" , method = RequestMethod.DELETE)
    @SystemLog(value = "删除实验项目", logo = "projectNumbers")
    public Result delete(@Valid ProInfoBaseDeleteParam param){
        proInfoBaseService.removeProject(param);
        return Result.success();
    }

    @ApiOperation(value = "根据条件查询一条实验项目基本表的数据")
    @RequestMapping(value = "/queryForOneRow" , method = RequestMethod.POST)
    public Result<ProInfoBaseVo> queryForOneRow(@Valid @RequestBody ProInfoBaseQueryForOneRowParam param){
        ProInfoBaseVo vo= this.proInfoBaseService.queryForOneRow(param);
        return Result.success(vo);
    }

    @ApiOperation(value = "查询子项目的基本信息")
    @RequestMapping(value = "/querySonMessage" , method = RequestMethod.POST)
    public Result<ProInfoBaseVo3> querySonMessage(@Valid @RequestBody ProInfoBaseQueryForOneRowParam param){

        return Result.success(this.proInfoBaseService.querySonMessage(param));
    }

    @ApiOperation(value = "根据条件分页查询实验项目基本表的数据")
    @RequestMapping(value = "/queryPage" , method = RequestMethod.POST)
    public Result<Page<ProInfoBaseVo>> queryPage(@Valid @RequestBody ProInfoBaseQueryPageParam param){
        Page<ProInfoBaseVo> voPage = this.proInfoBaseService.queryPage(param);
        return Result.success(voPage);
    }

    @ApiOperation(value = "项目检索编号生成")
    @GetMapping(value = "/itemGenerate")
    public Result<String> itemGenerate(@Valid @NotNull(message = "没有选择是子项目还是父项目")
                                           @RequestParam("isParent")boolean isParent) {
        log.info("开始生成项目检索编号");
        String projectNumber = this.proInfoBaseService.itemGenerate(isParent);
        return Result.success(projectNumber);
    }

    @ApiOperation(value = "父项目导入")
    @PostMapping(value = "/projectSuperImport")
    public Result projectSuperImport(@RequestBody MultipartFile file) {
        this.proInfoBaseService.importSuperProject(file);
        return Result.success();
    }

    @ApiOperation(value = "子项目导入")
    @PostMapping(value = "/projectSonImport")
    public Result projectSonImport(@RequestBody MultipartFile file) {
        this.proInfoBaseService.importSonProject(file);
        return Result.success();
    }

    @ApiOperation(value = "项目导出")
    @PostMapping(value = "/projectExport")
    public Result projectExport(@Valid @RequestBody ProjectExportParam param
            , HttpServletResponse response) {
        this.proInfoBaseService.projectExport(param, response);
        return Result.success();
    }
}
